package cn.tedu.ivos.geofence.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.geofence.pojo.dto.GeofenceParam;
import cn.tedu.ivos.geofence.pojo.dto.GeofenceQuery;
import cn.tedu.ivos.geofence.pojo.vo.GeofenceVO;
import cn.tedu.ivos.geofence.service.GeofenceService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Validated
@RestController
@RequestMapping("/v1/geofence/")
public class GeofenceController {
    @Autowired
    GeofenceService geofenceService;

    @ApiOperation("查询电子围栏")
    @GetMapping("select")
    public JsonResult selectAll(@Validated GeofenceQuery geofenceQuery) {
        log.debug("开始处理[查询电子围栏]的请求，geofenceQuery={}", geofenceQuery);
        List<GeofenceVO> list = geofenceService.selectAll(geofenceQuery);
        return JsonResult.ok(list);
    }

    @ApiOperation("保存或修改电子围栏")
    @PostMapping("save")
    public JsonResult saveGeofence(@Validated GeofenceParam geofenceParam) {
        log.debug("开始处理[保存电子围栏]的请求，geofenceParam={}", geofenceParam);
        geofenceService.saveGeofence(geofenceParam);
        return JsonResult.ok();
    }

    @ApiOperation("删除电子围栏")
    @PostMapping("delete/{id}")
    public JsonResult deleteGeofence(@PathVariable  Long id) {
        log.debug("开始处理[删除电子围栏]的请求，geoId={}", id);
        geofenceService.deleteGeofence(id);
        return JsonResult.ok();
    }
}
